#version 450

#extension GL_GOOGLE_include_directive : require
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : require

#include "../Brdf.glsl"
#include "../Lighting.glsl"


layout (location = 0) in vec2 inUV;


layout (location = 0) out vec4 outColor;


layout(set = 0, binding = 0) uniform sampler2D colorImage;


layout (push_constant) uniform PushConstants
{
    float exposure;
} pushConstants;

vec3 AcesFilm(vec3 x)
{
    float a = 2.51f;
    float b = 0.03f;
    float c = 2.43f;
    float d = 0.59f;
    float e = 0.14f;
    return clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0.0f, 1.0f);
}

void main()
{
    vec3 color = texture(colorImage, inUV).rgb;

    // Apply exposure
    color *= pushConstants.exposure;

    // HDR tonemap and gamma correct
    color = AcesFilm(color);
    color = pow(color, vec3(1.0 / 2.2));

    outColor = vec4(color, 1.0);
}
